home *** CD-ROM | disk | FTP | other *** search
- /*
- MOD 07-12-87 MAZ - RIFF I/O driver mainline
- */
- #include <Quickdraw.h>
- #include <WindowMgr.h>
- #include <FontMgr.h>
- #include <MenuMgr.h>
- #include <EventMgr.h>
- #include <DialogMgr.h>
- #include <FileMgr.h>
- #include <HFS.h>
- #include "MAZlib.h"
- #include <stdio.h>
- #include <xQuickdraw.h>
- #include <xWindowMgr.h>
- #include "RIFF.h"
-
- /* Low Memory Locations that LightSpeed C Doesn't Define */
- extern short MenuBarHeight: 0xBAA; /* height of menu bar */
-
- extern bool save_as_RIFF();
-
- extern short storage_type;
-
- Rect drag_limit_rect;
- Rect full_screen;
-
- MenuHandle apple_menu;
- MenuHandle file_menu;
-
- char last_file[256];
-
- /* in-memory picture definition */
- extern unsigned char *body[4];
- extern short nrows;
- extern short ncols;
- extern unsigned char *transfer_table;
-
- short desired_nsamples;
-
- main()
- {
- short menu_height;
-
- Stdio_MacInit(true);
- /* Macintosh Initialization */
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- TEInit();
- InitMenus();
- InitDialogs(0);
- InitCursor();
- Click_On(0);
- Init_stdio();
- SetWTitle(FrontWindow(),"\pRIFF I/O Driver");
- /* compute screen rectangle based on size of screen */
- drag_limit_rect = WMgrPort->portRect;
- if (ROM85 == 0)
- menu_height = 20; /* assume 20 for old ROM */
- else
- menu_height = MenuBarHeight; /* in low memory for new ROM */
- drag_limit_rect.top += menu_height;
- full_screen = drag_limit_rect;
- InsetRect(&drag_limit_rect, 4, 4);
- /* set up the menus */
- apple_menu = NewMenu(1, "\p\24");
- AddResMenu(apple_menu, 'DRVR');
- InsertMenu(apple_menu, 0);
- file_menu = NewMenu(2,"\pFile");
- AppendMenu(file_menu, "\pOpen RIFF.../O;Save as RIFF.../S;Quit/Q");
- DisableItem(file_menu, 2);
- body[0] = null;
- InsertMenu(file_menu, 0);
- DrawMenuBar();
- FlushEvents(-1, -1);
- InitCursor();
- forever
- mainevent();
- }
-
- mainevent()
- {
- bool b;
- char c;
- WindowPtr window;
- EventRecord event;
-
- SystemTask();
- b = GetNextEvent(everyEvent, &event);
- switch (event.what)
- {
- case nullEvent:
- break;
- case autoKey:
- case keyDown:
- c = event.message;
- if ((event.modifiers&cmdKey) != 0)
- domenu(MenuKey(c));
- break;
- case updateEvt:
- window = (WindowPtr)event.message;
- BeginUpdate(window);
- EndUpdate(window);
- break;
- case mouseDown:
- domousedown(&event);
- break;
- case mouseUp:
- break;
- }
- }
-
- /* process mouse down event */
- domousedown(e)
- EventRecord *e;
- {
- short i, window_code, ccode, toolsize, sh;
- long growResult;
- WindowPtr w;
- Handle h, h2;
- Rect *r;
- Point pt;
- Rect R;
- char pascal_string[256];
-
- /* see which window the mouse down is in */
- window_code = FindWindow(e->where, &w);
- /* pop windows forward by click here */
- if (w != null && w != FrontWindow())
- {
- SelectWindow(w);
- return;
- }
- /* handle menu hits */
- if (window_code == inMenuBar)
- {
- /* get menu hit and go to it */
- domenu(MenuSelect(e->where));
- /* and we're done */
- return;
- }
- /* handle desk accessories */
- if (window_code == inSysWindow)
- {
- SystemClick(e, w);
- /* and we're done */
- return;
- }
- /* test for drag of a window */
- if (window_code == inDrag)
- {
- /* do the dragging */
- DragWindow(w, e->where, &drag_limit_rect);
- /* and we're done */
- return;
- }
- /* test for goAway of window */
- if (window_code == inGoAway)
- {
- if (TrackGoAway(w, e->where))
- DisposeWindow(w);
- /* and we're done */
- return;
- }
- /* test for in zoom box (new ROM) */
- if (window_code == inZoomIn || window_code == inZoomOut)
- {
- /* Track the Zoom Box */
- if (TrackBox(w, e->where, window_code))
- /* Zoom the Window */
- ZoomWindow(w, window_code, false);
- /* done */
- return;
- }
- /* test for grow of edit window */
- if (window_code == inGrow)
- {
- /* grow the edit window */
- growResult = GrowWindow(w, e->where, &drag_limit_rect);
- /* adjust size of window if needed */
- if (growResult)
- SizeWindow(w, LoWord(growResult), HiWord(growResult), true);
- /* and we're done */
- return;
- }
- }
-
- domenu(menu_result)
- long menu_result;
- {
- short menu_id, item_number, sh, r, nsam,
- x_pic_aspect, y_pic_aspect, width, height;
- DialogPtr dptr;
- Rect R;
- char pascal_string[256];
- char filename[256];
-
- menu_id = HiWord(menu_result);
- item_number = LoWord(menu_result);
- switch (menu_id)
- {
- case 1:
- /* apple menu */
- /* a run-of-the-mill desk accessory */
- GetItem(apple_menu, item_number, pascal_string);
- /* open up the desk accessory */
- r = OpenDeskAcc(pascal_string);
- break;
- case 2:
- switch (item_number)
- {
- case 1:
- /* open riff in maximal precision format */
- open_RIFF(last_file, 256);
- if (body[0] != null)
- {
- DisableItem(file_menu, 1);
- EnableItem(file_menu, 2);
- printf("RIFF File \42%s\42 read in (%d rows, %d cols)\n",
- last_file, nrows, ncols);
- }
- break;
- case 2:
- /* save to RIFF */
- nsam = 65;
- if (storage_type == st_rgb)
- nsam = 256;
- if (save_as_RIFF(last_file, nsam))
- {
- printf("Saved as RIFF File \42%s\42\n", last_file);
- DisposPtr(body[0]);
- body[0] = null;
- DisposPtr(transfer_table);
- EnableItem(file_menu, 1);
- DisableItem(file_menu, 2);
- }
- break;
- case 3:
- HiliteMenu(0);
- ExitToShell();
- break;
- }
- break;
- }
- HiliteMenu(0);
- }
-